{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 导入需要的模块\n",
    "import requests\n",
    "import json\n",
    "\n",
    "# 输入密钥\n",
    "KEY = 'd4147415eb404d1fb95b61fdb32649ac'\n",
    "\n",
    "# 目标URL\n",
    "BASE_URL = 'https://apidyx.cognitiveservices.azure.com/face/v1.0/detect'\n",
    "\n",
    "# 请求头\n",
    "HEADERS = {\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': '{}'.format(KEY), \n",
    "}\n",
    "\n",
    "# 人脸相片地址\n",
    "img_url = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1604331597927&di=c58a9793832e866e2000a65082f8ec95&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201811%2F21%2F20181121235542_kofjh.jpg'\n",
    "data = {\n",
    "    'url': '{}'.format(img_url),\n",
    "}\n",
    "\n",
    "# 选择需要的人脸识别功能（根据API文档）\n",
    "payload = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'flase',\n",
    "    'returnFaceAttributes': '{}'.format('age,gender,glasses,emotion,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure'), \n",
    "}\n",
    "\n",
    "# 发送请求\n",
    "r = requests.post(BASE_URL,data=json.dumps(data),params = payload,headers=HEADERS)\n",
    "r.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'[{\"faceId\":\"6ebd3ceb-be7d-4580-a0d0-cc713eb524c8\",\"faceRectangle\":{\"top\":110,\"left\":649,\"width\":54,\"height\":54},\"faceAttributes\":{\"smile\":0.052,\"gender\":\"male\",\"age\":28.0,\"facialHair\":{\"moustache\":0.1,\"beard\":0.1,\"sideburns\":0.1},\"glasses\":\"NoGlasses\",\"emotion\":{\"anger\":0.0,\"contempt\":0.0,\"disgust\":0.0,\"fear\":0.0,\"happiness\":0.052,\"neutral\":0.943,\"sadness\":0.004,\"surprise\":0.0},\"blur\":{\"blurLevel\":\"low\",\"value\":0.16},\"exposure\":{\"exposureLevel\":\"goodExposure\",\"value\":0.59},\"makeup\":{\"eyeMakeup\":true,\"lipMakeup\":true},\"accessories\":[],\"occlusion\":{\"foreheadOccluded\":false,\"eyeOccluded\":false,\"mouthOccluded\":false},\"hair\":{\"bald\":0.05,\"invisible\":false,\"hairColor\":[{\"color\":\"black\",\"confidence\":0.98},{\"color\":\"brown\",\"confidence\":0.97},{\"color\":\"gray\",\"confidence\":0.2},{\"color\":\"other\",\"confidence\":0.19},{\"color\":\"red\",\"confidence\":0.1},{\"color\":\"blond\",\"confidence\":0.06},{\"color\":\"white\",\"confidence\":0.0}]}}},{\"faceId\":\"c7611910-a71b-4828-9ee7-f9453baef876\",\"faceRectangle\":{\"top\":235,\"left\":550,\"width\":52,\"height\":52},\"faceAttributes\":{\"smile\":0.999,\"gender\":\"male\",\"age\":21.0,\"facialHair\":{\"moustache\":0.1,\"beard\":0.1,\"sideburns\":0.1},\"glasses\":\"NoGlasses\",\"emotion\":{\"anger\":0.0,\"contempt\":0.0,\"disgust\":0.0,\"fear\":0.0,\"happiness\":0.999,\"neutral\":0.001,\"sadness\":0.0,\"surprise\":0.0},\"blur\":{\"blurLevel\":\"medium\",\"value\":0.44},\"exposure\":{\"exposureLevel\":\"goodExposure\",\"value\":0.63},\"makeup\":{\"eyeMakeup\":false,\"lipMakeup\":true},\"accessories\":[],\"occlusion\":{\"foreheadOccluded\":false,\"eyeOccluded\":false,\"mouthOccluded\":false},\"hair\":{\"bald\":0.08,\"invisible\":false,\"hairColor\":[{\"color\":\"brown\",\"confidence\":0.99},{\"color\":\"red\",\"confidence\":0.87},{\"color\":\"blond\",\"confidence\":0.45},{\"color\":\"other\",\"confidence\":0.14},{\"color\":\"black\",\"confidence\":0.13},{\"color\":\"gray\",\"confidence\":0.05},{\"color\":\"white\",\"confidence\":0.0}]}}},{\"faceId\":\"a12c7639-3957-4c51-88c6-59072a06d8b0\",\"faceRectangle\":{\"top\":232,\"left\":733,\"width\":52,\"height\":52},\"faceAttributes\":{\"smile\":0.845,\"gender\":\"male\",\"age\":23.0,\"facialHair\":{\"moustache\":0.1,\"beard\":0.1,\"sideburns\":0.1},\"glasses\":\"ReadingGlasses\",\"emotion\":{\"anger\":0.0,\"contempt\":0.001,\"disgust\":0.0,\"fear\":0.0,\"happiness\":0.845,\"neutral\":0.153,\"sadness\":0.001,\"surprise\":0.0},\"blur\":{\"blurLevel\":\"high\",\"value\":1.0},\"exposure\":{\"exposureLevel\":\"goodExposure\",\"value\":0.6},\"makeup\":{\"eyeMakeup\":false,\"lipMakeup\":true},\"accessories\":[],\"occlusion\":{\"foreheadOccluded\":false,\"eyeOccluded\":false,\"mouthOccluded\":false},\"hair\":{\"bald\":0.06,\"invisible\":false,\"hairColor\":[{\"color\":\"blond\",\"confidence\":0.99},{\"color\":\"gray\",\"confidence\":0.97},{\"color\":\"other\",\"confidence\":0.54},{\"color\":\"black\",\"confidence\":0.1},{\"color\":\"red\",\"confidence\":0.04},{\"color\":\"brown\",\"confidence\":0.04},{\"color\":\"white\",\"confidence\":0.0}]}}},{\"faceId\":\"fe7ba86a-e946-455f-9019-9307fe5f1f6a\",\"faceRectangle\":{\"top\":260,\"left\":186,\"width\":52,\"height\":52},\"faceAttributes\":{\"smile\":0.087,\"gender\":\"male\",\"age\":22.0,\"facialHair\":{\"moustache\":0.1,\"beard\":0.1,\"sideburns\":0.1},\"glasses\":\"NoGlasses\",\"emotion\":{\"anger\":0.0,\"contempt\":0.0,\"disgust\":0.0,\"fear\":0.0,\"happiness\":0.087,\"neutral\":0.911,\"sadness\":0.001,\"surprise\":0.0},\"blur\":{\"blurLevel\":\"medium\",\"value\":0.71},\"exposure\":{\"exposureLevel\":\"goodExposure\",\"value\":0.65},\"makeup\":{\"eyeMakeup\":true,\"lipMakeup\":true},\"accessories\":[],\"occlusion\":{\"foreheadOccluded\":false,\"eyeOccluded\":false,\"mouthOccluded\":false},\"hair\":{\"bald\":0.05,\"invisible\":false,\"hairColor\":[{\"color\":\"red\",\"confidence\":0.99},{\"color\":\"brown\",\"confidence\":0.98},{\"color\":\"other\",\"confidence\":0.47},{\"color\":\"blond\",\"confidence\":0.17},{\"color\":\"black\",\"confidence\":0.11},{\"color\":\"gray\",\"confidence\":0.01},{\"color\":\"white\",\"confidence\":0.0}]}}},{\"faceId\":\"49274b27-1b5d-4c68-872d-d0bdbe557b8d\",\"faceRectangle\":{\"top\":270,\"left\":354,\"width\":51,\"height\":51},\"faceAttributes\":{\"smile\":0.997,\"gender\":\"male\",\"age\":24.0,\"facialHair\":{\"moustache\":0.1,\"beard\":0.1,\"sideburns\":0.1},\"glasses\":\"NoGlasses\",\"emotion\":{\"anger\":0.0,\"contempt\":0.0,\"disgust\":0.0,\"fear\":0.0,\"happiness\":0.997,\"neutral\":0.003,\"sadness\":0.0,\"surprise\":0.0},\"blur\":{\"blurLevel\":\"low\",\"value\":0.1},\"exposure\":{\"exposureLevel\":\"goodExposure\",\"value\":0.71},\"makeup\":{\"eyeMakeup\":true,\"lipMakeup\":true},\"accessories\":[],\"occlusion\":{\"foreheadOccluded\":false,\"eyeOccluded\":false,\"mouthOccluded\":false},\"hair\":{\"bald\":0.17,\"invisible\":false,\"hairColor\":[{\"color\":\"blond\",\"confidence\":1.0},{\"color\":\"gray\",\"confidence\":0.64},{\"color\":\"brown\",\"confidence\":0.24},{\"color\":\"other\",\"confidence\":0.2},{\"color\":\"red\",\"confidence\":0.14},{\"color\":\"black\",\"confidence\":0.01},{\"color\":\"white\",\"confidence\":0.0}]}}},{\"faceId\":\"d58814a2-89ad-4725-a478-f02649f09200\",\"faceRectangle\":{\"top\":103,\"left\":473,\"width\":49,\"height\":49},\"faceAttributes\":{\"smile\":0.079,\"gender\":\"male\",\"age\":22.0,\"facialHair\":{\"moustache\":0.1,\"beard\":0.1,\"sideburns\":0.1},\"glasses\":\"NoGlasses\",\"emotion\":{\"anger\":0.0,\"contempt\":0.005,\"disgust\":0.0,\"fear\":0.0,\"happiness\":0.079,\"neutral\":0.914,\"sadness\":0.0,\"surprise\":0.001},\"blur\":{\"blurLevel\":\"high\",\"value\":1.0},\"exposure\":{\"exposureLevel\":\"goodExposure\",\"value\":0.64},\"makeup\":{\"eyeMakeup\":true,\"lipMakeup\":true},\"accessories\":[],\"occlusion\":{\"foreheadOccluded\":false,\"eyeOccluded\":false,\"mouthOccluded\":false},\"hair\":{\"bald\":0.47,\"invisible\":false,\"hairColor\":[{\"color\":\"other\",\"confidence\":0.96},{\"color\":\"blond\",\"confidence\":0.96},{\"color\":\"red\",\"confidence\":0.83},{\"color\":\"gray\",\"confidence\":0.59},{\"color\":\"black\",\"confidence\":0.05},{\"color\":\"brown\",\"confidence\":0.0},{\"color\":\"white\",\"confidence\":0.0}]}}},{\"faceId\":\"7fb42775-745a-4985-9118-0e7816873416\",\"faceRectangle\":{\"top\":97,\"left\":304,\"width\":49,\"height\":49},\"faceAttributes\":{\"smile\":0.001,\"gender\":\"male\",\"age\":23.0,\"facialHair\":{\"moustache\":0.1,\"beard\":0.1,\"sideburns\":0.1},\"glasses\":\"NoGlasses\",\"emotion\":{\"anger\":0.001,\"contempt\":0.015,\"disgust\":0.0,\"fear\":0.0,\"happiness\":0.001,\"neutral\":0.982,\"sadness\":0.002,\"surprise\":0.0},\"blur\":{\"blurLevel\":\"medium\",\"value\":0.34},\"exposure\":{\"exposureLevel\":\"goodExposure\",\"value\":0.65},\"makeup\":{\"eyeMakeup\":true,\"lipMakeup\":true},\"accessories\":[],\"occlusion\":{\"foreheadOccluded\":false,\"eyeOccluded\":false,\"mouthOccluded\":false},\"hair\":{\"bald\":0.46,\"invisible\":false,\"hairColor\":[{\"color\":\"gray\",\"confidence\":0.93},{\"color\":\"blond\",\"confidence\":0.89},{\"color\":\"other\",\"confidence\":0.76},{\"color\":\"black\",\"confidence\":0.61},{\"color\":\"red\",\"confidence\":0.05},{\"color\":\"brown\",\"confidence\":0.04},{\"color\":\"white\",\"confidence\":0.0}]}}}]'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': '6ebd3ceb-be7d-4580-a0d0-cc713eb524c8',\n",
       "  'faceRectangle': {'top': 110, 'left': 649, 'width': 54, 'height': 54},\n",
       "  'faceAttributes': {'smile': 0.052,\n",
       "   'gender': 'male',\n",
       "   'age': 28.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.052,\n",
       "    'neutral': 0.943,\n",
       "    'sadness': 0.004,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.16},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.59},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.05,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 0.98},\n",
       "     {'color': 'brown', 'confidence': 0.97},\n",
       "     {'color': 'gray', 'confidence': 0.2},\n",
       "     {'color': 'other', 'confidence': 0.19},\n",
       "     {'color': 'red', 'confidence': 0.1},\n",
       "     {'color': 'blond', 'confidence': 0.06},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': 'c7611910-a71b-4828-9ee7-f9453baef876',\n",
       "  'faceRectangle': {'top': 235, 'left': 550, 'width': 52, 'height': 52},\n",
       "  'faceAttributes': {'smile': 0.999,\n",
       "   'gender': 'male',\n",
       "   'age': 21.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.999,\n",
       "    'neutral': 0.001,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'medium', 'value': 0.44},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.63},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.08,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'brown', 'confidence': 0.99},\n",
       "     {'color': 'red', 'confidence': 0.87},\n",
       "     {'color': 'blond', 'confidence': 0.45},\n",
       "     {'color': 'other', 'confidence': 0.14},\n",
       "     {'color': 'black', 'confidence': 0.13},\n",
       "     {'color': 'gray', 'confidence': 0.05},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': 'a12c7639-3957-4c51-88c6-59072a06d8b0',\n",
       "  'faceRectangle': {'top': 232, 'left': 733, 'width': 52, 'height': 52},\n",
       "  'faceAttributes': {'smile': 0.845,\n",
       "   'gender': 'male',\n",
       "   'age': 23.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'ReadingGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.001,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.845,\n",
       "    'neutral': 0.153,\n",
       "    'sadness': 0.001,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'high', 'value': 1.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.6},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.06,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'blond', 'confidence': 0.99},\n",
       "     {'color': 'gray', 'confidence': 0.97},\n",
       "     {'color': 'other', 'confidence': 0.54},\n",
       "     {'color': 'black', 'confidence': 0.1},\n",
       "     {'color': 'red', 'confidence': 0.04},\n",
       "     {'color': 'brown', 'confidence': 0.04},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': 'fe7ba86a-e946-455f-9019-9307fe5f1f6a',\n",
       "  'faceRectangle': {'top': 260, 'left': 186, 'width': 52, 'height': 52},\n",
       "  'faceAttributes': {'smile': 0.087,\n",
       "   'gender': 'male',\n",
       "   'age': 22.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.087,\n",
       "    'neutral': 0.911,\n",
       "    'sadness': 0.001,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'medium', 'value': 0.71},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.65},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.05,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'red', 'confidence': 0.99},\n",
       "     {'color': 'brown', 'confidence': 0.98},\n",
       "     {'color': 'other', 'confidence': 0.47},\n",
       "     {'color': 'blond', 'confidence': 0.17},\n",
       "     {'color': 'black', 'confidence': 0.11},\n",
       "     {'color': 'gray', 'confidence': 0.01},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': '49274b27-1b5d-4c68-872d-d0bdbe557b8d',\n",
       "  'faceRectangle': {'top': 270, 'left': 354, 'width': 51, 'height': 51},\n",
       "  'faceAttributes': {'smile': 0.997,\n",
       "   'gender': 'male',\n",
       "   'age': 24.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.997,\n",
       "    'neutral': 0.003,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.1},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.71},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.17,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'blond', 'confidence': 1.0},\n",
       "     {'color': 'gray', 'confidence': 0.64},\n",
       "     {'color': 'brown', 'confidence': 0.24},\n",
       "     {'color': 'other', 'confidence': 0.2},\n",
       "     {'color': 'red', 'confidence': 0.14},\n",
       "     {'color': 'black', 'confidence': 0.01},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': 'd58814a2-89ad-4725-a478-f02649f09200',\n",
       "  'faceRectangle': {'top': 103, 'left': 473, 'width': 49, 'height': 49},\n",
       "  'faceAttributes': {'smile': 0.079,\n",
       "   'gender': 'male',\n",
       "   'age': 22.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.005,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.079,\n",
       "    'neutral': 0.914,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.001},\n",
       "   'blur': {'blurLevel': 'high', 'value': 1.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.64},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.47,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'other', 'confidence': 0.96},\n",
       "     {'color': 'blond', 'confidence': 0.96},\n",
       "     {'color': 'red', 'confidence': 0.83},\n",
       "     {'color': 'gray', 'confidence': 0.59},\n",
       "     {'color': 'black', 'confidence': 0.05},\n",
       "     {'color': 'brown', 'confidence': 0.0},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': '7fb42775-745a-4985-9118-0e7816873416',\n",
       "  'faceRectangle': {'top': 97, 'left': 304, 'width': 49, 'height': 49},\n",
       "  'faceAttributes': {'smile': 0.001,\n",
       "   'gender': 'male',\n",
       "   'age': 23.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.001,\n",
       "    'contempt': 0.015,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.001,\n",
       "    'neutral': 0.982,\n",
       "    'sadness': 0.002,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'medium', 'value': 0.34},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.65},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.46,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'gray', 'confidence': 0.93},\n",
       "     {'color': 'blond', 'confidence': 0.89},\n",
       "     {'color': 'other', 'confidence': 0.76},\n",
       "     {'color': 'black', 'confidence': 0.61},\n",
       "     {'color': 'red', 'confidence': 0.05},\n",
       "     {'color': 'brown', 'confidence': 0.04},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}}]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results = r.json()\n",
    "results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "face = [{'faceId': '6ebd3ceb-be7d-4580-a0d0-cc713eb524c8',\n",
    "  'faceRectangle': {'top': 110, 'left': 649, 'width': 54, 'height': 54},\n",
    "  'faceAttributes': {'smile': 0.052,\n",
    "   'gender': 'male',\n",
    "   'age': 28.0,\n",
    "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
    "   'glasses': 'NoGlasses',\n",
    "   'emotion': {'anger': 0.0,\n",
    "    'contempt': 0.0,\n",
    "    'disgust': 0.0,\n",
    "    'fear': 0.0,\n",
    "    'happiness': 0.052,\n",
    "    'neutral': 0.943,\n",
    "    'sadness': 0.004,\n",
    "    'surprise': 0.0},\n",
    "   'blur': {'blurLevel': 'low', 'value': 0.16},\n",
    "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.59},\n",
    "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
    "   'accessories': [],\n",
    "   'occlusion': {'foreheadOccluded': False,\n",
    "    'eyeOccluded': False,\n",
    "    'mouthOccluded': False},\n",
    "   'hair': {'bald': 0.05,\n",
    "    'invisible': False,\n",
    "    'hairColor': [{'color': 'black', 'confidence': 0.98},\n",
    "     {'color': 'brown', 'confidence': 0.97},\n",
    "     {'color': 'gray', 'confidence': 0.2},\n",
    "     {'color': 'other', 'confidence': 0.19},\n",
    "     {'color': 'red', 'confidence': 0.1},\n",
    "     {'color': 'blond', 'confidence': 0.06},\n",
    "     {'color': 'white', 'confidence': 0.0}]}}},\n",
    " {'faceId': 'c7611910-a71b-4828-9ee7-f9453baef876',\n",
    "  'faceRectangle': {'top': 235, 'left': 550, 'width': 52, 'height': 52},\n",
    "  'faceAttributes': {'smile': 0.999,\n",
    "   'gender': 'male',\n",
    "   'age': 21.0,\n",
    "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
    "   'glasses': 'NoGlasses',\n",
    "   'emotion': {'anger': 0.0,\n",
    "    'contempt': 0.0,\n",
    "    'disgust': 0.0,\n",
    "    'fear': 0.0,\n",
    "    'happiness': 0.999,\n",
    "    'neutral': 0.001,\n",
    "    'sadness': 0.0,\n",
    "    'surprise': 0.0},\n",
    "   'blur': {'blurLevel': 'medium', 'value': 0.44},\n",
    "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.63},\n",
    "   'makeup': {'eyeMakeup': False, 'lipMakeup': True},\n",
    "   'accessories': [],\n",
    "   'occlusion': {'foreheadOccluded': False,\n",
    "    'eyeOccluded': False,\n",
    "    'mouthOccluded': False},\n",
    "   'hair': {'bald': 0.08,\n",
    "    'invisible': False,\n",
    "    'hairColor': [{'color': 'brown', 'confidence': 0.99},\n",
    "     {'color': 'red', 'confidence': 0.87},\n",
    "     {'color': 'blond', 'confidence': 0.45},\n",
    "     {'color': 'other', 'confidence': 0.14},\n",
    "     {'color': 'black', 'confidence': 0.13},\n",
    "     {'color': 'gray', 'confidence': 0.05},\n",
    "     {'color': 'white', 'confidence': 0.0}]}}},\n",
    " {'faceId': 'a12c7639-3957-4c51-88c6-59072a06d8b0',\n",
    "  'faceRectangle': {'top': 232, 'left': 733, 'width': 52, 'height': 52},\n",
    "  'faceAttributes': {'smile': 0.845,\n",
    "   'gender': 'male',\n",
    "   'age': 23.0,\n",
    "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
    "   'glasses': 'ReadingGlasses',\n",
    "   'emotion': {'anger': 0.0,\n",
    "    'contempt': 0.001,\n",
    "    'disgust': 0.0,\n",
    "    'fear': 0.0,\n",
    "    'happiness': 0.845,\n",
    "    'neutral': 0.153,\n",
    "    'sadness': 0.001,\n",
    "    'surprise': 0.0},\n",
    "   'blur': {'blurLevel': 'high', 'value': 1.0},\n",
    "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.6},\n",
    "   'makeup': {'eyeMakeup': False, 'lipMakeup': True},\n",
    "   'accessories': [],\n",
    "   'occlusion': {'foreheadOccluded': False,\n",
    "    'eyeOccluded': False,\n",
    "    'mouthOccluded': False},\n",
    "   'hair': {'bald': 0.06,\n",
    "    'invisible': False,\n",
    "    'hairColor': [{'color': 'blond', 'confidence': 0.99},\n",
    "     {'color': 'gray', 'confidence': 0.97},\n",
    "     {'color': 'other', 'confidence': 0.54},\n",
    "     {'color': 'black', 'confidence': 0.1},\n",
    "     {'color': 'red', 'confidence': 0.04},\n",
    "     {'color': 'brown', 'confidence': 0.04},\n",
    "     {'color': 'white', 'confidence': 0.0}]}}},\n",
    " {'faceId': 'fe7ba86a-e946-455f-9019-9307fe5f1f6a',\n",
    "  'faceRectangle': {'top': 260, 'left': 186, 'width': 52, 'height': 52},\n",
    "  'faceAttributes': {'smile': 0.087,\n",
    "   'gender': 'male',\n",
    "   'age': 22.0,\n",
    "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
    "   'glasses': 'NoGlasses',\n",
    "   'emotion': {'anger': 0.0,\n",
    "    'contempt': 0.0,\n",
    "    'disgust': 0.0,\n",
    "    'fear': 0.0,\n",
    "    'happiness': 0.087,\n",
    "    'neutral': 0.911,\n",
    "    'sadness': 0.001,\n",
    "    'surprise': 0.0},\n",
    "   'blur': {'blurLevel': 'medium', 'value': 0.71},\n",
    "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.65},\n",
    "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
    "   'accessories': [],\n",
    "   'occlusion': {'foreheadOccluded': False,\n",
    "    'eyeOccluded': False,\n",
    "    'mouthOccluded': False},\n",
    "   'hair': {'bald': 0.05,\n",
    "    'invisible': False,\n",
    "    'hairColor': [{'color': 'red', 'confidence': 0.99},\n",
    "     {'color': 'brown', 'confidence': 0.98},\n",
    "     {'color': 'other', 'confidence': 0.47},\n",
    "     {'color': 'blond', 'confidence': 0.17},\n",
    "     {'color': 'black', 'confidence': 0.11},\n",
    "     {'color': 'gray', 'confidence': 0.01},\n",
    "     {'color': 'white', 'confidence': 0.0}]}}},\n",
    " {'faceId': '49274b27-1b5d-4c68-872d-d0bdbe557b8d',\n",
    "  'faceRectangle': {'top': 270, 'left': 354, 'width': 51, 'height': 51},\n",
    "  'faceAttributes': {'smile': 0.997,\n",
    "   'gender': 'male',\n",
    "   'age': 24.0,\n",
    "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
    "   'glasses': 'NoGlasses',\n",
    "   'emotion': {'anger': 0.0,\n",
    "    'contempt': 0.0,\n",
    "    'disgust': 0.0,\n",
    "    'fear': 0.0,\n",
    "    'happiness': 0.997,\n",
    "    'neutral': 0.003,\n",
    "    'sadness': 0.0,\n",
    "    'surprise': 0.0},\n",
    "   'blur': {'blurLevel': 'low', 'value': 0.1},\n",
    "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.71},\n",
    "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
    "   'accessories': [],\n",
    "   'occlusion': {'foreheadOccluded': False,\n",
    "    'eyeOccluded': False,\n",
    "    'mouthOccluded': False},\n",
    "   'hair': {'bald': 0.17,\n",
    "    'invisible': False,\n",
    "    'hairColor': [{'color': 'blond', 'confidence': 1.0},\n",
    "     {'color': 'gray', 'confidence': 0.64},\n",
    "     {'color': 'brown', 'confidence': 0.24},\n",
    "     {'color': 'other', 'confidence': 0.2},\n",
    "     {'color': 'red', 'confidence': 0.14},\n",
    "     {'color': 'black', 'confidence': 0.01},\n",
    "     {'color': 'white', 'confidence': 0.0}]}}},\n",
    " {'faceId': 'd58814a2-89ad-4725-a478-f02649f09200',\n",
    "  'faceRectangle': {'top': 103, 'left': 473, 'width': 49, 'height': 49},\n",
    "  'faceAttributes': {'smile': 0.079,\n",
    "   'gender': 'male',\n",
    "   'age': 22.0,\n",
    "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
    "   'glasses': 'NoGlasses',\n",
    "   'emotion': {'anger': 0.0,\n",
    "    'contempt': 0.005,\n",
    "    'disgust': 0.0,\n",
    "    'fear': 0.0,\n",
    "    'happiness': 0.079,\n",
    "    'neutral': 0.914,\n",
    "    'sadness': 0.0,\n",
    "    'surprise': 0.001},\n",
    "   'blur': {'blurLevel': 'high', 'value': 1.0},\n",
    "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.64},\n",
    "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
    "   'accessories': [],\n",
    "   'occlusion': {'foreheadOccluded': False,\n",
    "    'eyeOccluded': False,\n",
    "    'mouthOccluded': False},\n",
    "   'hair': {'bald': 0.47,\n",
    "    'invisible': False,\n",
    "    'hairColor': [{'color': 'other', 'confidence': 0.96},\n",
    "     {'color': 'blond', 'confidence': 0.96},\n",
    "     {'color': 'red', 'confidence': 0.83},\n",
    "     {'color': 'gray', 'confidence': 0.59},\n",
    "     {'color': 'black', 'confidence': 0.05},\n",
    "     {'color': 'brown', 'confidence': 0.0},\n",
    "     {'color': 'white', 'confidence': 0.0}]}}},\n",
    " {'faceId': '7fb42775-745a-4985-9118-0e7816873416',\n",
    "  'faceRectangle': {'top': 97, 'left': 304, 'width': 49, 'height': 49},\n",
    "  'faceAttributes': {'smile': 0.001,\n",
    "   'gender': 'male',\n",
    "   'age': 23.0,\n",
    "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
    "   'glasses': 'NoGlasses',\n",
    "   'emotion': {'anger': 0.001,\n",
    "    'contempt': 0.015,\n",
    "    'disgust': 0.0,\n",
    "    'fear': 0.0,\n",
    "    'happiness': 0.001,\n",
    "    'neutral': 0.982,\n",
    "    'sadness': 0.002,\n",
    "    'surprise': 0.0},\n",
    "   'blur': {'blurLevel': 'medium', 'value': 0.34},\n",
    "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.65},\n",
    "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
    "   'accessories': [],\n",
    "   'occlusion': {'foreheadOccluded': False,\n",
    "    'eyeOccluded': False,\n",
    "    'mouthOccluded': False},\n",
    "   'hair': {'bald': 0.46,\n",
    "    'invisible': False,\n",
    "    'hairColor': [{'color': 'gray', 'confidence': 0.93},\n",
    "     {'color': 'blond', 'confidence': 0.89},\n",
    "     {'color': 'other', 'confidence': 0.76},\n",
    "     {'color': 'black', 'confidence': 0.61},\n",
    "     {'color': 'red', 'confidence': 0.05},\n",
    "     {'color': 'brown', 'confidence': 0.04},\n",
    "     {'color': 'white', 'confidence': 0.0}]}}}]\n",
    "\n",
    "glass={}\n",
    "smiling={}\n",
    "hair_color={}\n",
    "age={}\n",
    "gender={}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "眼镜： {'Person1': 'NoGlasses', 'Person2': 'NoGlasses', 'Person3': 'ReadingGlasses', 'Person4': 'NoGlasses', 'Person5': 'NoGlasses', 'Person6': 'NoGlasses', 'Person7': 'NoGlasses'}\n",
      "微笑指数： {'Person1': 0.052, 'Person2': 0.999, 'Person3': 0.845, 'Person4': 0.087, 'Person5': 0.997, 'Person6': 0.079, 'Person7': 0.001}\n",
      "头发颜色： {'Person1': 'black', 'Person2': 'brown', 'Person3': 'blond', 'Person4': 'red', 'Person5': 'blond', 'Person6': 'other', 'Person7': 'gray'}\n",
      "年龄： {'Person1': 28.0, 'Person2': 21.0, 'Person3': 23.0, 'Person4': 22.0, 'Person5': 24.0, 'Person6': 22.0, 'Person7': 23.0}\n",
      "性别： {'Person1': 'male', 'Person2': 'male', 'Person3': 'male', 'Person4': 'male', 'Person5': 'male', 'Person6': 'male', 'Person7': 'male'}\n"
     ]
    }
   ],
   "source": [
    "count = 0\n",
    "while count < len(face):\n",
    "    glass[\"Person{}\".format(count + 1)] = face[count]['faceAttributes']['glasses']\n",
    "    smiling[\"Person{}\".format(count + 1)] = face[count]['faceAttributes']['smile']\n",
    "    hair_color[\"Person{}\".format(count + 1)] = face[count]['faceAttributes']['hair']['hairColor'][0]['color']\n",
    "    age[\"Person{}\".format(count + 1)] = face[count]['faceAttributes']['age']\n",
    "    gender[\"Person{}\".format(count + 1)] = face[count]['faceAttributes']['gender']\n",
    "    count += 1\n",
    "    \n",
    "print(\"眼镜：\", glass)\n",
    "print(\"微笑指数：\", smiling)\n",
    "print(\"头发颜色：\", hair_color)\n",
    "print(\"年龄：\", age)\n",
    "print(\"性别：\", gender)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
